interface CanCompare<T>
Interface CanCompare<T>
specifies that a class can be compared to an object of type T
, producing a signed comparison int
. This interface allows overloading of the <
, >
, <=
, and >=
operators. If any of these operators is applied, the appropriate compare(T)
method will be called and tested. This interface also supports the ==
operator through CanEqual<T>
.
Modifiers | Return Types | Method and Description |
---|---|---|
public readonly |
(int) |
compare(T other) Method called when the |
public readonly compare(T other) => (int)
Method called when the <
, >
, <=
, or >=
operator is applied. Should return -1
, 0
, or 1
, if the current object is smaller than, equal to, or larger than the other object, respectively. The relation defined by this method should be transitive.
other
- object to compare to
whether smaller, equal, or larger